<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar clearfix" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<!-- <el-form-item>
					<el-input v-model="filters.name" placeholder="设备IP"></el-input>
				</el-form-item> -->
				<el-form-item>
					<el-button type="primary" @click="screenEdit">查询</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-show="my_permi.indexOf('flowExtemal.export') > -1 || my_permi.indexOf('admin') > -1" @click="exportT">导出</el-button>
				</el-form-item>
				<el-form-item v-show="my_permi.indexOf('systemConfig.shipang') > -1 || my_permi.indexOf('admin') > -1">
					<el-button type="primary" @click="shiBang" v-show="is_shibang == '0'">开始试磅</el-button>
					<el-button type="primary" @click="shiBang" v-show="is_shibang == '1'">结束试磅</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="showPrint('waibu')">打印设置</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<div id="drag-table" class="drag-table" :style="{height: clientHeight+'px'}">
			<table cellspacing="0">
				<tr class="t-top">
					<th v-slldrag style="min-width: 80px;"><div class="table-cell"><div class="span">制卡时间</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">IC卡卡号</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">印刷编号</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">流程类型</div></div></th>
					<th v-slldrag style="min-width: 100px;"><div class="table-cell"><div class="span">司机身份证号码</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">车牌号</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">初称信息</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">采购重量</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">卸货重量</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">误差重量</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">出门重量</div></div></th>
					<th v-slldrag style="min-width: 100px;"><div class="table-cell"><div class="span">是否可以出门</div></div></th>
					<th v-slldrag style="min-width: 100px;"><div class="table-cell"><div class="span">地磅净重（卸）</div></div></th>
					<th v-slldrag style="min-width: 100px;"><div class="table-cell"><div class="span">地磅净重（装）</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">回称信息</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">是否过磅</div></div></th>
					<th v-slldrag style="min-width: 100px;"><div class="table-cell"><div class="span">误差重量（卸）</div></div></th>
					<th v-slldrag style="min-width: 100px;"><div class="table-cell"><div class="span">误差重量（装）</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">误差比值</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">是否成功</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">是否完成</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">完成时间</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">是否退货</div></div></th>
					<th v-slldrag style="min-width: 100px;"><div class="table-cell"><div class="span">是否可以出门</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">异常备案</div></div></th>
					<th v-slldrag><div class="table-cell"><div class="span">操作</div></div></th>
				</tr>
				<tr class="t-body" v-for="(item, index) in cardList" :key="index" :class="(item.weightdata && item.weightdata.is_finished == 'Y') ? 'is_finished_tr' : 'no_finished_tr'">
					<td style="min-width: 80px;"><div class="table-cell"><div class="span">{{item.system_datetime}}</div></div></td>
					<td><div class="table-cell"><div class="span">{{item.ic_id}}</div></div></td>
					<td><div class="table-cell"><div class="span">{{item.ic_print_code}}</div></div></td>
					<td><div class="table-cell"><div class="span" v-if="item.weightdata">{{item.weightdata.process_number_desc}}</div></div></td>
					<td style="min-width: 100px;"><div class="table-cell"><div class="span">{{item.sfz_number}}</div></div></td>
					<td><div class="table-cell"><div class="span" v-if="item.weightdata">{{item.weightdata.vehicle_number}}</div></div></td>
					<td><div class="table-cell"><div class="span"><el-button v-if="item.weightdata" size="small" type="primary" @click="viewDetails1(index)">查看</el-button></div></div></td>
					<td>
						<div class="table-cell">
							<div class="span"
								v-if="item.flow_extemal&&item.weightdata"
								style="display: block"
							>
								{{(item.weightdata.process_number == 'SALEBACK' || item.weightdata.process_number == 'PURCHASE') ? item.flow_extemal.purchase_weight : '0'}}
							</div>
							<el-button size="small" type="warning"
							style="display: inline-block"
							 v-if="item.flow_extemal&&item.weightdata"
							 v-show="(my_permi.indexOf('flowExtemal.purchase_weight.put') > -1 || my_permi.indexOf('admin') > -1) && (item.weightdata.process_number == 'SALEBACK' || item.weightdata.process_number == 'PURCHASE') && item.weightdata.is_finished !== 'Y'"
							 @click="handleEdit(index, item, 'purchase_weight')">查看</el-button>
						</div>
					</td>
					<td>
						<div class="table-cell">
							<div class="span" v-if="item.flow_extemal&&item.weightdata" style="display: block">{{(item.weightdata.process_number == 'SALEBACK' || item.weightdata.process_number == 'PURCHASE') ? item.flow_extemal.discharge_weight : '0'}}</div>
							<el-button size="small" type="warning"
							style="display: inline-block"
							v-if="item.flow_extemal&&item.weightdata"
							v-show="(my_permi.indexOf('flowExtemal.discharge_weight.put') > -1 || my_permi.indexOf('admin') > -1) && (item.weightdata.process_number == 'SALEBACK' || item.weightdata.process_number == 'PURCHASE') && item.weightdata.is_finished !== 'Y'"
							@click="handleEdit(index, item, 'discharge_weight')"
							>查看</el-button>
						</div>
					</td>
					<td>
						<div class="table-cell">
							<div class="span" v-if="item.flow_extemal&&item.weightdata" style="">{{(item.weightdata.process_number == 'SALEBACK' || item.weightdata.process_number == 'PURCHASE') ? item.flow_extemal.relative_weight : '0'}}</div>
						</div>
					</td>
					<td>
						<div class="table-cell">
							<div class="span" v-if="item.weightdata" style="display: block">{{(item.weightdata.process_number == 'SALE') ? item.flow_extemal.out_weight : 0}}</div>
							<el-button size="small" type="warning"
							style="display: inline-block"
							v-if="item.flow_extemal&&item.weightdata"
							v-show="(my_permi.indexOf('flowExtemal.out_weight.put') > -1 || my_permi.indexOf('admin') > -1) && item.weightdata.process_number == 'SALE' && item.weightdata.is_finished !== 'Y'"
							@click="handleEdit(index, item, 'out_weight')"
							>查看</el-button>
						</div>
					</td>
					<td style="min-width: 100px;">
						<div class="table-cell">
							<div class="span" v-if="item.flow_extemal">{{item.flow_extemal.is_go_desc}}</div>
						</div>
					</td>
					<td style="min-width: 100px;">
						<div class="table-cell">
							<div class="span" v-if="item.flow_extemal&&item.weightdata" style="">{{(item.weightdata.process_number == 'SALEBACK' || item.weightdata.process_number == 'PURCHASE') ? item.flow_extemal.net_weight : '0'}}</div>
						</div>
					</td>
					<td style="min-width: 100px;">
						<div class="table-cell">
							<div class="span" v-if="item.weightdata" style="">{{(item.weightdata.process_number == 'SALE') ? item.weightdata.net_weight : 0}}</div>
						</div>
					</td>
					<td>
						<div class="table-cell">
							<div class="span">
								<el-button size="small" v-if="item.weightdata" type="primary" @click="viewDetails2(index)">查看</el-button>
							</div>
						</div>
					</td>
					<td>
						<div class="table-cell">
							<div class="span" v-if="item.weightdata">{{item.weightdata.is_finished_desc}}
							</div>
						</div>
					</td>
					<td style="min-width: 100px;">
						<div class="table-cell">
							<div class="span" v-if="item.flow_extemal&&item.weightdata" style="">{{(item.weightdata.process_number == 'SALEBACK' || item.weightdata.process_number == 'PURCHASE') ? item.weightdata.weight_error : '0'}}</div>
						</div>
					</td>
					<td style="min-width: 100px;">
						<div class="table-cell">
							<div class="span" v-if="item.weightdata" style="">{{(item.weightdata.process_number == 'SALE') ? item.weightdata.weight_error : 0}}</div>
						</div>
					</td>
					<td><div class="table-cell"><div class="span" v-if="item.weightdata">{{item.weightdata.weight_error_ratio}}</div></div></td>
					<td><div class="table-cell"><div class="span" v-if="item.weightdata">{{item.weightdata.is_finished_desc}}</div></div></td>
					<td><div class="table-cell"><div class="span" v-if="item.weightdata">{{item.weightdata.is_success_desc}}</div></div></td>
					<td><div class="table-cell"><div class="span" v-if="item.weightdata">{{item.weightdata.second_readic_datetime}}</div></div></td>
					<td>
						<div class="table-cell">
							<div class="span" v-if="item.flow_extemal" style="display: block;">{{item.flow_extemal.is_return_desc}}</div>
							<el-button size="small" type="warning"
							style="display: inline-block"
							v-if="item.flow_extemal && item.weightdata"
							v-show="(my_permi.indexOf('flowExtemal.is_return.put') > -1 || my_permi.indexOf('admin') > -1) && item.weightdata.is_finished !== 'Y'"
							@click="handleEdit(index, item, 'is_return')"
							>修改</el-button>
						</div>
					</td>
					<td style="min-width: 100px;">
						<div class="table-cell">
							<div class="span" v-if="item.flow_extemal" style="display: block;">{{item.flow_extemal.is_go_desc}}</div>
							<!-- <div v-if="item.flow_extemal && item.weightdata && item.weightdata.is_finished == 'Y' && item.flow_extemal.is_go_desc == ''">系统允许出门</div>
							<div v-else-if="item.flow_extemal && item.weightdata && item.weightdata.is_finished == 'N' && item.flow_extemal.is_go_desc != ''">人工允许出门</div>
							<div v-else>不允许出门</div> -->
							<el-button size="small" type="warning"
							style="display: inline-block"
							v-if="item.flow_extemal && item.weightdata && item.weightdata.is_finished !== 'Y'"
							v-show="(my_permi.indexOf('flowExtemal.is_go.put') > -1 || my_permi.indexOf('admin') > -1)"
							@click="handleEdit(index, item, 'is_go')"
							>修改</el-button>
						</div>
					</td>
					<td>
						<div class="table-cell">
							<div class="span" v-if="item.flow_extemal" style="display: block;">{{item.flow_extemal.remarks}}</div>
							<el-button size="small" type="warning"
							style="display: inline-block"
							v-if="item.flow_extemal && item.weightdata"
							v-show="(my_permi.indexOf('flowExtemal.remark.put') > -1 || my_permi.indexOf('admin') > -1) && item.weightdata.is_finished !== 'Y'"
							@click="handleEdit(index, item, 'remarks')"
							>修改</el-button>
						</div>
					</td>
					<td>
						<div class="table-cell">
							<el-button size="small" type="primary" @click="showPrint('', index, item)">打印</el-button>
						</div>
					</td>
				</tr>
			</table>
	    </div>

		<!--工具条-->
		<!-- <el-col :span="24" class="toolbar">
			<el-pagination
				layout="prev, pager, next"
				@current-change="handleCurrentChange"
				:total="total"
				style="float:right;">
			</el-pagination>
		</el-col> -->

		<!-- 图片放大 -->
		<el-dialog title="展示图片" v-model="is_zoom_img" class="zoom-img-dialog" :close-on-click-modal="false">
			<img class="zoom_img_id" :src="zoom_img">
		</el-dialog>

		<!--查看初称、回称界面-->
		<el-dialog title="初次称重信息" v-model="detailsVisible" :close-on-click-modal="false">
			<div class="weightD"><span>初称刷卡时间：</span> <span>{{details.first_readic_datetime}}</span></div>
			<div class="weightD"><span>初称重量：</span> <span>{{details.first_weight}}</span></div>
			<!-- <div class="weightD"><span>初称地磅编号：</span> <span>{{details.first_wbid}}</span></div> -->
			<div class="weightD"><span>初称车辆抓拍图片：</span> <img :src="details.first_capvh_path +'/'+ details.first_capvh_filename" @click="isZoom(details.first_capvh_path +'/'+ details.first_capvh_filename)"><span class="print-btn" @click="printBtn(details.first_capvh_path +'/'+ details.first_capvh_filename)">打印</span></div>
			<div class="weightD"><span>初称地磅抓拍A：</span> <img :src="details.first_cap_a_path +'/'+ details.first_cap_a_fielname" @click="isZoom(details.first_cap_a_path +'/'+details.first_cap_a_fielname)"><span class="print-btn" @click="printBtn(details.first_capvh_path +'/'+ details.first_capvh_filename)">打印</span></div>
			<div class="weightD"><span>初称地磅抓拍B：</span> <img :src="details.first_cap_b_path +'/'+ details.first_cap_b_fielname" @click="isZoom(details.first_cap_b_path +'/'+details.first_cap_b_fielname)"><span class="print-btn" @click="printBtn(details.first_capvh_path +'/'+ details.first_capvh_filename)">打印</span></div>
		</el-dialog>

		<!--查看初称、回称界面-->
		<el-dialog title="回次称重信息" v-model="detailsVisible2" :close-on-click-modal="false">
			<div class="weightD"><span>回称刷卡时间：</span> <span>{{details.second_readic_datetime}}</span></div>
			<div class="weightD"><span>回称重量：</span> <span>{{details.second_weight}}</span></div>
			<!-- <div class="weightD"><span>回称地磅编号：</span> <span>{{details.second_wbid}}</span></div> -->
			<div class="weightD"><span>回称车辆抓拍图片：</span> <img :src="details.second_capvh_path +'/'+ details.second_capvh_filename" @click="isZoom(details.second_capvh_path +'/'+details.second_capvh_filename)"></div>
			<div class="weightD"><span>回称地磅抓拍A：</span> <img :src="details.second_cap_a_path +'/'+ details.second_cap_a_fielname" @click="isZoom(details.second_cap_a_path +'/'+details.second_cap_a_fielname)"></div>
			<div class="weightD"><span>回称地磅抓拍A：</span> <img :src="details.second_cap_b_path +'/'+ details.second_cap_b_fielname" @click="isZoom(details.second_cap_b_path +'/'+details.second_cap_b_fielname)"></div>
		</el-dialog>

		<!--编辑界面-->
		<el-dialog :title="title" v-model="editFormVisible" :close-on-click-modal="false">
			<el-form :model="editForm" label-width="120px" ref="editForm">
				<!-- <el-form-item label="处理情况">
					<el-select v-model="editForm.handling_situation" placeholder="请选择">
					    <el-option
					      v-for="item in options"
					      :key="item.value"
					      :label="item.label"
					      :value="item.value">
					    </el-option>
					</el-select>
				</el-form-item> -->
				<el-form-item :label="title" v-if="editType == 'purchase_weight'">
					<el-input v-model="editForm.purchase_weight" auto-complete="off"></el-input>
				</el-form-item>
				<!-- 修改卸货重量 PUT -->
				<el-form-item :label="title" v-if="editType == 'discharge_weight'">
					<el-input v-model="editForm.discharge_weight" auto-complete="off"></el-input>
				</el-form-item>
				<!-- 修改提货重量 PUT -->
				<el-form-item :label="title" v-if="editType == 'pick_weight'">
					<el-input v-model="editForm.pick_weight" auto-complete="off"></el-input>
				</el-form-item>
				<!-- 修改出门重量 PUT -->
				<el-form-item :label="title" v-if="editType == 'out_weight'">
					<el-input v-model="editForm.out_weight" auto-complete="off"></el-input>
				</el-form-item>
				<!-- 修改异常备案 -->
				<el-form-item :label="title" v-if="editType == 'remarks'">
					<el-input v-model="editForm.remarks" auto-complete="off"></el-input>
				</el-form-item>
				<!-- 修改是否退货 -->
				<el-form-item :label="title" v-if="editType == 'is_return'">
					<el-select v-model="editForm.is_return" placeholder="请选择">
					    <el-option
					      v-for="item in is_return_arr"
					      :key="item.value"
					      :label="item.label"
					      :value="item.value">
					    </el-option>
					</el-select>
				</el-form-item>
				<!-- 修改是否可以出门 -->
				<el-form-item :label="title" v-if="editType == 'is_go'">
					<el-select v-model="editForm.is_go" placeholder="请选择">
					    <el-option
					      v-for="item in is_go_arr"
					      :key="item.value"
					      :label="item.label"
					      :value="item.value">
					    </el-option>
					</el-select>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
			</div>
		</el-dialog>

        <!-- 筛选界面 -->
        <el-dialog title="筛选" v-model="screenFormVisible" :close-on-click-modal="false">
            <el-form :model="screenForm" label-width="110px" ref="screenForm">
            	<el-form-item label="开始至结束时间">
	                <el-date-picker
	                  v-model="screenForm.currentdate"
	                  type="daterange"
	                  range-separator="至"
	                  placeholder="请选择开始和结束时间">
	                </el-date-picker>
	            </el-form-item>
                <el-form-item label="是否成功">
                	<span class="change-val" @click="changeval('is_finished', 'Y')">
                		<span class="change-val-span" v-if="screenForm.is_finished == 'N' || screenForm.is_finished == ''"></span>
                		<span class="change-val-span change-active" v-else></span>
                		是
                	</span>
                	<span class="change-val" @click="changeval('is_finished', 'N')">
                		<span class="change-val-span" v-if="screenForm.is_finished == 'Y' || screenForm.is_finished == ''"></span>
                		<span class="change-val-span change-active" v-else></span>
	                	否
	                </span>
                </el-form-item>
                <el-form-item label="是否完成">
                	<span class="change-val" @click="changeval('is_success', 'Y')">
                		<span class="change-val-span" v-if="screenForm.is_success == 'N' || screenForm.is_success == ''"></span>
                		<span class="change-val-span change-active" v-else></span>
                		出厂过磅成功
                	</span>
                	<span class="change-val" @click="changeval('is_success', 'N')">
                		<span class="change-val-span" v-if="screenForm.is_success == 'Y' || screenForm.is_success == ''"></span>
                		<span class="change-val-span change-active" v-else></span>
	                	出厂过磅失败
	                </span>
                </el-form-item>
                <el-form-item label="流程类型">
            		<el-radio v-model="screenForm.process_number" label="SALE">销售提货</el-radio>
  					<el-radio v-model="screenForm.process_number" label="SALEBACK">销售退货</el-radio>
  					<el-radio v-model="screenForm.process_number" label="PURCHASE">采购收货</el-radio>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="screenFormVisible = false">取消</el-button>
                <el-button type="primary" @click.native="screenSubmit" :loading="screenLoading">提交</el-button>
            </div>
        </el-dialog>

		<!--打印界面-->
		<el-dialog title="打印" v-model="printFormVisible" :close-on-click-modal="false">
			<el-form label-width="110px" ref="printForm">
				<el-checkbox-group v-model="checkList">
					<el-checkbox v-for="item in checkListArr" :label="item" :key="item">{{item}}</el-checkbox>
				</el-checkbox-group>
			</el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="printFormVisible = false">取消</el-button>
                <el-button type="primary" @click.native="printSubmit" :loading="printLoading">提交</el-button>
            </div>
		</el-dialog>
	</section>
</template>

<script>
	import { flowExtemal, flowExtemalEdit, isReturn, isGo, BASEURL, isShibang, systemConfig, printConfig, printConfigPost } from '@/api/api';
    import { mapState } from 'vuex'
	export default {
		data() {
			return {
				filters: {
					name: ''
				},
				cardList: [],
				total: 0,
				page: 1,
				listLoading: false,
				is_zoom_img: false,
				zoom_img: '',
				detailsVisible: false,
				details: {},
				detailsVisible2: false,
				// 编辑采购重量
				editFormVisible: false,
				editForm: {
					// purchase_weight: '',
				},
				title: '',
				editLoading: false,
				editText: '',
				editType: '',
				is_return_arr: [],
				is_go_arr: [],
                screenFormVisible: false,//新增界面是否显示
                screenLoading: false,
                //新增界面数据
                screenForm: {
                    is_finished: '',
                    is_success: '',
                    currentdate: [],
                    process_number: '',
                },
				is_shibang: '',
				checkListArr: [],
				checkList: [],
				printFormVisible: false,
				printLoading: false,
				is_print: '',
				clientHeight: document.getElementById('app').clientHeight - 200
			}
		},
        computed: {
            ...mapState(
                {
                  'my_permi': state => state.my_permi,
                  // 'clientHeight': state => state.clientHeight
                }
            )
        },
		methods: {
			router(path) {
				this.$router.push(path)
			},
			handleCurrentChange(val) {
				this.page = val;
				this.flowExtemal(this.screenForm);
			},
			changeval(type, val) {
				if(type == 'is_finished'){
					this.screenForm.is_finished = (this.screenForm.is_finished == val) ? "" : val;
				}else if(type == 'is_success'){
					this.screenForm.is_success = (this.screenForm.is_success == val) ? "" : val;
				}
			},
			//获取设备警报信息
			flowExtemal(para) {
                let paras = '';//`page=${this.page}`;
                if(para){
                    if(para.currentdate.length>0){
						let begin = new Date(para.currentdate[0]);
						let end = new Date(para.currentdate[1]);
						paras += `&start_time=${begin.getFullYear() + '-' + (begin.getMonth()+1) + '-' + begin.getDate()}`;
						paras += `&end_time=${end.getFullYear() + '-' + (end.getMonth()+1) + '-' + end.getDate() + ' 23:59:59'}`;
                    }
                    if(para.is_finished){
                      paras += `&is_finished=${para.is_finished}`
                    }
                    if(para.is_success){
                      paras += `&is_success=${para.is_success}`
                    }
                    if(para.process_number){
                      paras += `&process_number=${para.process_number}`
                    }
                }
				this.listLoading = true;
				flowExtemal(paras).then((res) => {
					if(res.data.status.errCode == '10002'){
						sessionStorage.removeItem('token');
						this.$message({
							message: res.data.status.message,
							type: 'warning'
				        });
				        setTimeout(() =>{
				        	this.router({path: '/login'})
				        }, 1500);
						return;
					}
					// this.total = res.data.data.total
					this.cardList = res.data.data
					this.listLoading = false
				});
			},
			isZoom(imgSrc) {
				this.zoom_img = imgSrc
				this.is_zoom_img = !this.is_zoom_img
			},
			// 查看初称详情
			viewDetails1(index) {
				this.detailsVisible = true
				this.details = this.cardList[index].weightdata
			},
			// 查看回称详情
			viewDetails2(index) {
				this.detailsVisible2 = true
				this.details = this.cardList[index].weightdata
			},
			//显示编辑界面
			handleEdit: function (index, row, type) {
				this.editText = row.order_systemnumber
				switch(type) {
					case 'purchase_weight':
						this.editType = 'purchase_weight';
						this.editForm = {
							purchase_weight: row.flow_extemal.purchase_weight,
						};
						this.title = '修改采购重量'
						break;
					case 'discharge_weight':
						this.editType = 'discharge_weight';
						this.editForm = {
							discharge_weight: row.flow_extemal.discharge_weight,
						};
						this.title = '修改卸货重量'
						break;
					case 'pick_weight':
						this.editType = 'pick_weight';
						this.editForm = {
							pick_weight: row.flow_extemal.pick_weight,
						};
						this.title = '修改提货重量'
						break;
					case 'out_weight':
						this.editType = 'out_weight';
						this.editForm = {
							out_weight: row.flow_extemal.out_weight,
						};
						this.title = '修改出门重量'
						break;
					case 'is_return':
						this.editType = 'is_return';
						this.editForm = {
							is_return: row.flow_extemal.is_return,
						};
						this.title = '是否退货'
						break;
					case 'is_go':
						this.editType = 'is_go';
						this.editForm = {
							is_go: row.flow_extemal.is_go,
						};
						this.title = '是否可以出门'
						break;
					case 'remarks':
						this.editType = 'remarks';
						this.editForm = {
							remarks: row.flow_extemal.remarks,
						};
						this.title = '修改异常备案'
						break;
				}
				this.editFormVisible = true;
			},
			//编辑
			editSubmit: function () {
				this.$refs.editForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
							this.editLoading = true;
							let para = Object.assign({}, this.editForm);
							flowExtemalEdit(this.editText, this.editType, para).then((res) => {
								if(res.data.status.errCode != '0'){
									this.$message({
										message: res.data.status.message,
										type: 'error'
									});
								}else{
									this.$message({
										message: res.data.status.message,
										type: 'success'
									});
								}
								this.editLoading = false;
								this.$refs['editForm'].resetFields();
								this.editFormVisible = false;
								this.flowExtemal(this.screenForm);
							}).catch((err) => {
								console.dir(err)
							});
						});
					}
				});
			},
            //显示查询界面
            screenEdit: function () {
                this.screenFormVisible = true;
                this.screenForm = this.screenForm
            },
            //查询
            screenSubmit: function () {
                this.screenLoading = true;
                let para = Object.assign({}, this.screenForm);
                this.screenFormVisible = false;
				this.flowExtemal(para);
                this.screenLoading = false
            },
            // 打印界面
            showPrint (type, index, row) {
                this.printFormVisible = true;
                this.is_print = '';
            	if(type){
                	this.is_print = 'waibu';
            		this.checkListArr = ['车牌号,vehicle_number','制卡时间,system_datetime','IC卡卡号,ic_id','印刷编号,ic_print_code','流程类型,process_number_desc','司机身份证号码,sfz_number','采购重量,purchase_weight','卸货重量,discharge_weight','误差重量,relative_weight','提货重量,pick_weight','出门重量,out_weight','地磅净重（卸）,net_weight','地磅净重（装）,net_weight','是否过磅,is_finished_desc','误差重量（卸）,weight_error','误差重量（装）,weight_error','误差比值,weight_error_ratio','是否成功,is_finished_desc','是否完成,is_success_desc','完成时间,second_readic_datetime','是否退货,is_return_desc','是否可以出门,is_go_desc','异常备案,remarks'];
					this.getPrintConfig();
					return
            	}
                if(!row.weightdata || !row.flow_extemal){
                	this.$message({
						message: '该条数据有误，不能打印',
						type: 'error'
	                });
                	this.printFormVisible = false;
                	return;
                }
				this.is_print = '';
            	this.checkListArr = [`车牌号: ${row.weightdata.vehicle_number}`, `制卡时间: ${row.system_datetime}`, `IC卡卡号: ${row.ic_id}`, `印刷编号: ${row.ic_print_code}`, `流程类型: ${row.weightdata.process_number_desc}`, `司机身份证号码: ${row.sfz_number}`, `采购重量: ${(row.weightdata.process_number == 'SALEBACK' || row.weightdata.process_number == 'PURCHASE') ? row.flow_extemal.purchase_weight : '0'}`, `卸货重量: ${(row.weightdata.process_number == 'SALEBACK' || row.weightdata.process_number == 'PURCHASE') ? row.flow_extemal.discharge_weight : '0'}`, `误差重量: ${(row.weightdata.process_number == 'SALEBACK' || row.weightdata.process_number == 'PURCHASE') ? row.flow_extemal.relative_weight : '0'}`, `提货重量: ${(row.weightdata.process_number == 'SALE') ? row.flow_extemal.pick_weight : 0}`, `出门重量: ${(row.weightdata.process_number == 'SALE') ? row.flow_extemal.out_weight : 0}`, `地磅净重（卸）: ${(row.weightdata.process_number == 'SALEBACK' || row.weightdata.process_number == 'PURCHASE') ? row.flow_extemal.net_weight : '0'}`, `地磅净重（装）: ${(row.weightdata.process_number == 'SALE') ? row.weightdata.net_weight : 0}`, `是否过磅: ${row.weightdata.is_finished_desc}`, `误差重量（卸）: ${(row.weightdata.process_number == 'SALEBACK' || row.weightdata.process_number == 'PURCHASE') ? row.weightdata.weight_error : '0'}`, `误差重量（装）: ${(row.weightdata.process_number == 'SALE') ? row.weightdata.weight_error : 0}`, `误差比值: ${row.weightdata.weight_error_ratio}`, `是否成功: ${row.weightdata.is_finished_desc}`, `是否完成: ${row.weightdata.is_success_desc}`, `完成时间: ${row.weightdata.second_readic_datetime}`, `是否退货: ${row.flow_extemal.is_return_desc}`, `是否可以出门: ${row.flow_extemal.is_go_desc}`, `异常备案: ${row.flow_extemal.remarks}`];
            	this.getPrintConfig();
            },
            getPrintConfig() {
				printConfig().then((res) =>{
                	let dataList = res.data.data;
                	for(var i=0; i<this.checkListArr.length; i++){
                		for(var j=0; j<dataList.length; j++){
                			if(this.checkListArr[i].indexOf(dataList[j].name) > -1 && dataList[j].type == '3'){
                				if(this.checkList.indexOf(this.checkListArr[i]) < 0){
                					this.checkList.push(this.checkListArr[i])
                				}
                			}
                		}
                	}
                })
            },
            printSubmit () {
	            var str = this.checkList.join('*');
	            sessionStorage.setItem('printing', str);
                this.printFormVisible = false;
                this.printLoading = false;
                if(this.is_print){
	            	let dataJson = {}
            		var otherArr = [];
            		for(var i=0; i<this.checkList.length; i++){
            			var newArr = this.checkList[i].split(',');
            			for(var j=0; j<newArr.length; j++){
            				var otherArr2 = {
								"identity": newArr[1],
								"name": newArr[0],
								"value":"1"
							}
            			}
            			otherArr.push(otherArr2);
            		}
					dataJson={
						// 3为外部车辆
						"type":"3",
						"othor": otherArr
					}
	            	printConfigPost(dataJson).then((res) => {
	            		console.log(res)
	            	}).catch((err) => {
	            		console.dir(err)
	            	})
	            }else{
	    			let routeData = this.$router.resolve({path: '/print'});
	    			window.open(routeData.href, '_blank');
	            }
            },
            printBtn(path) {
				sessionStorage.setItem('printing', path);
    			let routeData = this.$router.resolve({path: '/print', query:{img : 'img'}});
    			window.open(routeData.href, '_blank');
            },
			is_return() {
				isReturn().then((res) => {
					this.is_return_arr = [];
					for(var i in res.data.data){
						var arr = {
							label: res.data.data[i].value,
							value: res.data.data[i].key,
						}
						this.is_return_arr.push(arr)
					}
				}).catch((err) => {
					console.dir(err)
				})
			},
			is_go() {
				isGo().then((res) => {
					this.is_go_arr = [];
					for(var i in res.data.data){
						var arr = {
							label: res.data.data[i].value,
							value: res.data.data[i].key,
						}
						this.is_go_arr.push(arr)
					}
				}).catch((err) => {
					console.dir(err)
				})
			},
			exportT() {
				let para = this.screenForm;
				let paras = '';
                if(para){
                    if(para.currentdate.length>0){
						let begin = new Date(para.currentdate[0]);
						let end = new Date(para.currentdate[1]);
						paras += `&start_time=${begin.getFullYear() + '-' + (begin.getMonth()+1) + '-' + begin.getDate()}`;
						paras += `&end_time=${end.getFullYear() + '-' + (end.getMonth()+1) + '-' + end.getDate() + ' 23:59:59'}`;
                    }
                    if(para.is_finished){
                      paras += `&is_finished=${para.is_finished}`
                    }
                    if(para.is_success){
                      paras += `&is_success=${para.is_success}`
                    }
                    if(para.process_number){
                      paras += `&process_number=${para.process_number}`
                    }
                }
				location.href=`${BASEURL}/flow/export?token=${sessionStorage.token}${paras}&pageSize=${sessionStorage.getItem('pagesize')}`;
			},
			shiBang() {
				isShibang().then((res) => {
					console.log(res)
					if(res.data.status.errCode == '0'){
						location.reload()
					}
				}).catch((err) => {
					console.dir(err)
				})
			},
			systemconfig() {
				systemConfig().then((res) => {
					for(var i in res.data.data){
						if(res.data.data[i].identity == 'trial_weight'){
							this.is_shibang = res.data.data[i].deviation
						}
					}
				}).catch((err) => {
					console.log(err)
				})
			}
		},
		mounted() {
			this.flowExtemal();
			this.is_return()
			this.is_go()
			this.systemconfig();
			var table = document.getElementById("drag-table");
			var th = table.getElementsByTagName('th');
			for (var j = 0; j < th.length; j++) {
			  th[j].onmousemove = function(e) {
			    //更改鼠标样式
			    if (e.offsetX > this.offsetWidth - 10)
			      this.style.cursor = 'col-resize';
			    else
			      this.style.cursor = 'move';
			  };
			}
		}
	};

</script>

<style>
.print-btn{
	margin-left: 15px;
	font-size: 16px;
    cursor: pointer;
}
.change-val{
	margin-right: 15px;
	cursor: pointer;
}
.change-val-span{
	border: 1px solid #bfcbd9;
	border-radius: 100px;
	width: 18px;
	height: 18px;
	display: inline-block;
	vertical-align: middle;
	box-sizing: border-box;
	position: relative;
	top: -1px;
}
.change-val-span.change-active:after{
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #fff;
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    -ms-transform: translate(-50%,-50%) scale(0);
    transform: translate(-50%,-50%) scale(0);
    transition: transform .15s cubic-bezier(.71,-.46,.88,.6);
    transform: translate(-50%,-50%) scale(1);
}
.change-val-span.change-active{
    border-color: #20a0ff;
    background: #20a0ff;
}
.drag-table{
	position: relative;   /*定位*/
	-moz-user-select: none;
	-khtml-user-select: none;
	user-select: none;
	clear: both;
	width: 100%;
	overflow: auto;
}
.drag-table table{
	width: 200%;
	position: relative;
	border-top: 1px solid rgba(216, 216, 216);
	border-right: 1px solid rgba(216, 216, 216);
}
.drag-table .t-top{
	background-color: #eef1f6;
}
.drag-table .t-top th{
	cursor: move;
}
.drag-table tr{
	display: flex;
	width: 100%;
}
.drag-table .t-top th, .drag-table .t-body td{
	border-left: 1px solid rgba(216, 216, 216);
	border-bottom: 1px solid rgba(216, 216, 216);
	box-sizing: border-box;
	text-align: center;
	padding: 6px 5px;
	flex: 1;
    font-size: 12px;
    min-width: 60px;
}
.drag-table .t-top th .table-cell, .drag-table .t-body td .table-cell{
    display: table;
    text-align: center;
    width: 100%;
    height: 100%;
    position: relative
}
.drag-table .t-top th .table-cell div.span, .drag-table .t-body td .table-cell div.span{
    display: table-cell;
    vertical-align: middle;
    white-space: normal;
    word-break: break-all;
}
.drag-table .t-body td .table-cell .el-icon-edit{
	position: absolute;
	right: 0;
	cursor: pointer;
}
.drag-table tr.is_finished_tr{
	background-color: #f7f7f7;
}
</style>
